//
//  MYNewsShopDetailsHotelOrderInfoCell.swift
//  MuYing
//
//  Created by tbb on 2020/3/9.
//  Copyright © 2020 TBB. All rights reserved.
//

import UIKit

class MYNewsShopDetailsHotelOrderInfoCell: YQTableViewBaseCell,UITextFieldDelegate {
    
    @objc var textFiledBlock:((_ :NSString,_ :Int)->())?
    
    @objc var indexPath:NSIndexPath?
    
    
    @objc @IBOutlet weak var textField: UITextField!
    @objc @IBOutlet weak var titleBtn: QMUIButton!
    override func awakeFromNib() {
        super.awakeFromNib()
        self.textField.delegate = self;
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}

extension MYNewsShopDetailsHotelOrderInfoCell {
    func textFieldDidEndEditing(_ textField: UITextField) {
        if let textFiledBlock = self.textFiledBlock, let indexPath = self.indexPath {
            textFiledBlock(textField.text as NSString? ?? "",indexPath.row)
        }
    }
    
    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        var toBeStr = textField.text
        let rag = toBeStr?.toRange(range)
        toBeStr = toBeStr?.replacingCharacters(in: rag!, with: string)
        if let textFiledBlock = self.textFiledBlock, let indexPath = self.indexPath,let str = toBeStr  {
            textFiledBlock(str as NSString,indexPath.row)
        }
        return true;
    }
    
}
